package com.example.medicalapp.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.example.medicalapp.fragment.DoctorRegisterFragment;
import com.example.medicalapp.fragment.LoginFragment;
import com.example.medicalapp.fragment.RegisterFragment;

public class AuthPagerAdapter extends FragmentStateAdapter {
    private boolean isDoctor;

    public AuthPagerAdapter(@NonNull FragmentActivity fragmentActivity, boolean isDoctor) {
        super(fragmentActivity);
        this.isDoctor = isDoctor;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        // 根据位置返回对应的Fragment
        switch (position) {
            case 0:
                // 登录Fragment，传递是否为医生的标识
                return LoginFragment.newInstance(isDoctor);
            case 1:
                // 注册Fragment，医生和患者使用不同的Fragment
                if (isDoctor) {
                    return DoctorRegisterFragment.newInstance();
                } else {
                    return RegisterFragment.newInstance();
                }
            default:
                return LoginFragment.newInstance(isDoctor);
        }
    }

    @Override
    public int getItemCount() {
        // 只有两个页面：登录和注册
        return 2;
    }
}

